import os
import sys
import time
sys.path.append(os.path.abspath(os.path.join(
    os.path.dirname(__file__), '../bin')))
from tools import getActivityPostsHtml
import pdb

def _main():
    activityName = ''
    dayOffset = 0
    if len(sys.argv) > 1:
        activityName = sys.argv[1]
    else:
        activityName = '惜时社'

    if len(sys.argv) > 2:
        dayOffset = int(sys.argv[2])

    if len(sys.argv) > 3:
        pdb.set_trace()

    posts = getActivityPostsHtml(activityName, dayOffset)

    if posts is None:
        return

    postsPath = os.path.abspath(os.path.join(os.path.dirname(__file__), '../output/{}{}.html'.format(activityName, dayOffset)))
    fo = open(postsPath, "w", encoding='utf-8')
    text = posts
    fo.write(text)
    # print('{}: {}'.format(time.asctime(time.localtime(time.time())), text))
    fo.close()

if __name__ == '__main__':
    _main()